/**
 * axios拦截器配置
*/
import {
    addPending, removePending, cancelPending,
} from './cancel-request'
import axios from 'axios'
// 请求拦截器
axios.interceptors.request.use(
    request => {
        // 发送请求前首先检查该请求是否已经重复，重复则进行取消并移除
        cancelPending(request)
        // 添加该请求到pendingList中
        addPending(request)
        return request
    },
    error => {
        // return Promise.  error(error)
    }
)
axios.interceptors.response.use(
    response => {
        // 请求成功去除pengding状态
        removePending(response)
        if (response.status === 200) {
            return Promise.resolve(response)
        } else {
            return Promise.reject(response)
        }
    },
    error => {
        // 请求失败去除pengding状态
        removePending(error.response)
        return Promise.reject(error.response)
    }
)